package iterator

import "errors"

type tArrayStackIterator struct {
	stack *tArrayStack
	index int
}

func newArrayStackIterator(stack *tArrayStack) IIterator {
	return &tArrayStackIterator{
		stack,
		0,
	}
}

func (me *tArrayStackIterator) More() bool {
	return me.index < me.stack.size
}

func (me *tArrayStackIterator) Next() (error, interface{}) {
	if me.index >= me.stack.size {
		return errors.New("no more elements"), nil
	}

	it := me.stack.items[me.index]
	me.index++
	return nil, it
}
